// pages/component/input-license/input-license.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabIndex: '0',
    code: [{
      value: ''
    }, {
      value: ''
    }, {
      value: ''
    }, {
      value: ''
    }, {
      value: ''
    }, {
      value: ''
    }, {
      value: ''
    }],
    currentFocus: 0,
    isFocus: false,
    showKeyBoard: false,
    license_color: '0',
    license_plate: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  // 输入省份
  inputProvince: function (e) {
    var temp = this.data.code;
    temp[0].value = e.detail;
    this.setData({
      code: temp,
      currentFocus: 1
    })
  },
  // 输入城市
  inputCity: function (e) {
    var temp = this.data.code;
    temp[1].value = e.detail;
    this.setData({
      code: temp,
      currentFocus: 2
    })
  },

  //输入车牌
  inputLicense: function (e) {
    var temp = this.data.code;
    var i = this.data.currentFocus
    temp[i].value = e.detail;
    this.setData({
      code: temp,
      currentFocus: i + 1
    })
  },


  // 退格 
  backspace: function (e) {
    var i = e.detail
    console.log(i)
    var temp = this.data.code;
    temp[i].value = '';
    this.setData({
      code: temp,
      currentFocus: i
    })
  },

  closeKeyBoard: function () {
    this.setData({
      showKeyBoard: false,
      isFocus: false
    })
  },

  openKeyBoard: function () {
    this.setData({
      showKeyBoard: true,
      isFocus: true
    })
    this.keyboard = this.selectComponent("#keyboard");
    this.keyboard.loadkeyboard(this.data.currentFocus, this.data.tabIndex)
  },

  // 切换车牌
  changeTab: function (e) {
    console.log(e)
    this.setData({
      tabIndex: e.currentTarget.dataset.index,
      currentFocus: 0
    })
    if (e.currentTarget.dataset.index == '1') {
      this.setData({
        code: [{
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }]
      })
      this.data.license_color = '4'
    } else {
      this.setData({
        code: [{
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }, {
          value: ''
        }]
      })
      this.data.license_color = '0'
    }
  },
})